<?php

class User extends AbstractPhlame
{
    const TABLE = 'users';
    
    protected $name = 'NoName';
    protected $email = 'default@mail.ph';
    
    protected $lastOnline = 0;
    
    /**
     * User's lastaction older than 200secs
     * @return bool
     */
    public function isOnline()
    {
        return time() - $this->lastOnline > 200 ? false : true;
    }
    
    /**
     * @return int/timestamp
     */
    public function lastActionTime()
    {
        return $this->lastOnline;
    }
    
    /**
     * Set User's lastaction time to now
     */
    public function resetLastAction()
    {
        $this->lastOnline = time();
    }
    
    public function getName()
    {
        return $this->name;
    }
    
    public function setName($name)
    {
        if (!Validator::isName($name)) {
            throw new InvalidArgumentException('Invalid name given');
        }
        $this->name = (string) $name;
    }
    
    public function getEmail()
    {
        return $this->email;
    }
    
    public function setEmail($email)
    {
        if (!Validator::isEmail($email)) {
            throw new InvalidArgumentException('Invalid email given');
        }
        $this->email = (string) $email;
    }
}

class UserException extends PhlameException
{}